<?php 
namespace Home\Model;
use Think\Model;
/*
	ng广告模板类
*/
class AdModel extends Model {

	//插入广告模板
	/*
	 *@param array $data 数据数组
	 */
	public function insert_ad($data){
		$result = M('Ad')->add($data);
		return $result;
	}
	
	//查询广告模板
	/*
	 *@param int $id 用户id
	 *@param array return 列表
	 */
	public function select_ad_list($uid,$limit,$field='*'){
		$result = M('Ad')->where('uid = %d',$uid)->order('status desc,id desc')->limit($limit)->field($field)->select();
		return $result;
	}
	
	//查询广告模板单条
	/*
	 *@param int $uid 用户id
	 *@param int $tid 模板id
	 */
	public function select_ad($uid,$tid){
		$result = M('Ad')->where('uid = %d and id = %d',$uid,$tid)->find();
		return $result;
	}
	
	
	/*
	 *@param int $tid 模板id
	 *@param array $data 更新数据
	 *@param int $tid 模板id
	 */
	//更新广告模板
	public function update_ad($tid,$data,$uid){
		$result = M('Ad')->where('id = %d and uid = %d',$tid,$uid)->save($data);
		return $result;
	}
	
	/*
	 *@param int $uid 用户id
	 *@param int $tid 模板id
	 */
	//删除广告模板
	public function delete_ad($uid,$tid){
		$result = M('Ad')->where('uid = %d and id = %d',$uid,$tid)->delete();
		return $result;
	}
	
	
}
